package com.liam.micro.consumer.controller;


import com.liam.micro.consumer.vo.UserVo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import org.springframework.web.client.RestTemplate;

@RestController
@RequestMapping("consumer")
public class UserController {

    @Autowired
    private RestTemplate restTemplate;

    @GetMapping("user/{id}")
    public UserVo getUserById(@PathVariable("id") Integer id){
        String url = String.format("http://%s/api/user/%s","micro-provider",id);
        return  restTemplate.getForObject(url,UserVo.class);
    }
}
